/**
 * Author: Shen Yanqiu
 * Date: 2018-02-27
 * Time: 9:39
 *
 */
import modelExtend from 'dva-model-extend';
import {pageModel} from '../../common';
import {message} from 'antd';
import { delay } from "utils";


export default modelExtend(pageModel, {
  namespace: 'satisfactionStatisticsDetails',
  state: {
    detailsInfo: {},
  },
  subscriptions: {
    setup ({ dispatch, history }) {
      history.listen((location) => {

      });
    },
  },
  effects: {
    * refreshDetails ({ payload: id }, { call, put }) {
      console.log(id);
      const detailsInfo = {
        exponent: [{
          id: 1,
          name: "不满意",
          proportion: "65",
        }, {
          id: 2,
          name: "满意",
          proportion: "80",
        }, {
          id: 3,
          name: "非常满意",
          proportion: "45",
        }],
        details: [{
          id: 1,
          name: "不满意",
          reason: "反正不好看",
        }, {
          id: 2,
          name: "满意",
          reason: "就是不好看",
        }, {
          id: 3,
          name: "非常满意",
          reason: "不好看",
        }],
      };
      // const { data } = yield call(getSatisfactionStatisticsDetails, id);
      yield put({
        type: 'updateDetailsInfo',
        payload: {
          detailsInfo,
        },
      });
      yield delay(1000);
    },
  },
  reducers: {
    updateDetailsInfo (state, { payload: { detailsInfo } }) {
      return { ...state, ...{ detailsInfo } };
    },
  },
});
